package com.demo.controller;

import com.demo.service.BaseService;
import com.demo.tool.ReturnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
//日志
@Slf4j
//验证参数
@Validated //加了后@NoNull之类的注解才能生效，如果只是@valid注解则不需要加上
public abstract class BaseController<T,Q,K>{

    @Autowired
    private BaseService<T,Q> baseService;


    @GetMapping("/all")
    protected ReturnResult findAll(Integer page, Integer pageSize,Q query) throws ParseException {
        System.out.println(page+"控制器当前页");
        System.out.println(pageSize+"控制器页数量");
        return ReturnResult.success(baseService.findAllpaging(page,pageSize,query));

    }


    @PostMapping("/add")
    protected ReturnResult save( @RequestBody T t){
        return ReturnResult.success(baseService.save(t));
    }

    @PostMapping("/del")
    protected ReturnResult del(K[] ids){
      return ReturnResult.success(baseService.delByIdIn((Serializable[]) ids));

    }

    @PutMapping("/edit")
    protected ReturnResult edit(@RequestBody T t){
       return ReturnResult.success(baseService.update(t));
    }
}
